package com.ruoyi.web.controller.production.fertilizer;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.production.domain.fertilizer.FertilizerType;
import com.ruoyi.production.service.fertilizer.IFertilizerTypeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 化肥类型Controller
 *
 * @author ruoyi
 * @date 2021-07-12
 */
@RestController
@RequestMapping("/production/fertilizerType")
public class FertilizerTypeController extends BaseController
{
    @Autowired
    private IFertilizerTypeService fertilizerTypeService;

    /**
     * 查询化肥类型列表
     */
    @PreAuthorize("@ss.hasPermi('production:fertilizerType:list')")
    @GetMapping("/list")
    public TableDataInfo list(FertilizerType fertilizerType)
    {
        startPage();
        List<FertilizerType> list = fertilizerTypeService.selectFertilizerTypeList(fertilizerType);
        return getDataTable(list);
    }

    /**
     * 导出化肥类型列表
     */
    @PreAuthorize("@ss.hasPermi('production:fertilizerType:export')")
    @Log(title = "化肥类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(FertilizerType fertilizerType)
    {
        List<FertilizerType> list = fertilizerTypeService.selectFertilizerTypeList(fertilizerType);
        ExcelUtil<FertilizerType> util = new ExcelUtil<FertilizerType>(FertilizerType.class);
        return util.exportExcel(list, "化肥类型数据");
    }

    /**
     * 获取化肥类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('production:fertilizerType:query')")
    @GetMapping(value = "/{fertilizerTypeId}")
    public AjaxResult getInfo(@PathVariable("fertilizerTypeId") Long fertilizerTypeId)
    {
        return AjaxResult.success(fertilizerTypeService.selectFertilizerTypeById(fertilizerTypeId));
    }

    /**
     * 新增化肥类型
     */
    @PreAuthorize("@ss.hasPermi('production:fertilizerType:add')")
    @Log(title = "化肥类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FertilizerType fertilizerType)
    {
        return toAjax(fertilizerTypeService.insertFertilizerType(fertilizerType));
    }

    /**
     * 修改化肥类型
     */
    @PreAuthorize("@ss.hasPermi('production:fertilizerType:edit')")
    @Log(title = "化肥类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FertilizerType fertilizerType)
    {
        return toAjax(fertilizerTypeService.updateFertilizerType(fertilizerType));
    }

    /**
     * 删除化肥类型
     */
    @PreAuthorize("@ss.hasPermi('production:fertilizerType:remove')")
    @Log(title = "化肥类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fertilizerTypeIds}")
    public AjaxResult remove(@PathVariable Long[] fertilizerTypeIds)
    {
        return toAjax(fertilizerTypeService.deleteFertilizerTypeByIds(fertilizerTypeIds));
    }
}
